package com.budwk.app.util.poiUtils;

import cn.hutool.core.date.DateUtil;
import com.budwk.app.sqfw.models.Sqfw_Sms_Msg;
import com.budwk.app.util.poiUtils.excelPictureConfigBO.ExcelFileCreateParamBO;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.List;
import java.util.Map;

/**
 * @author XYD-PC021
 * @project dfxy-shequ
 * @description 短信下载
 * @date 2024/1/16 15:36:10
 */
public class SmsMsgExcelUtils {

    public static String downExcel(List<Sqfw_Sms_Msg> smsMsgList) {

        Map<String, Object> threeDetailedParamMap = Maps.newHashMap();

        List<Map<String, Object>> dataList = Lists.newArrayList();

        if (smsMsgList == null || smsMsgList.size() == 0) {
            Map<String, Object> rollDataMap = Maps.newHashMap();
            rollDataMap.put("num", null);
            rollDataMap.put("name", null);
            rollDataMap.put("address", null);
            rollDataMap.put("userName", null);
            rollDataMap.put("phone", null);
            rollDataMap.put("createDate", null);

            dataList.add(rollDataMap);

        } else {
            int num = 0;
            for (Sqfw_Sms_Msg smsMsg : smsMsgList) {
                num ++;
                Map<String, Object> rollDataMap = Maps.newHashMap();
                rollDataMap.put("num", num);
                rollDataMap.put("name", smsMsg.getName());
                rollDataMap.put("address", smsMsg.getAddress());
                rollDataMap.put("userName", smsMsg.getUserName());
                rollDataMap.put("phone", smsMsg.getPhone());
                rollDataMap.put("createDate", DateUtil.format(smsMsg.getCreateDate(), "yyyy/MM/dd HH:mm:ss"));

                dataList.add(rollDataMap);
            }
        }

        String templatePath = CommonFormOfficeUtils.getTemplatePathByOS("smsMsg.xlsx");
        String fileName = "短信发送记录";

        ExcelFileCreateParamBO excelFileCreateParam = new ExcelFileCreateParamBO();
        excelFileCreateParam.setTemplatePath(templatePath);
        excelFileCreateParam.setSheetParam(threeDetailedParamMap);
        excelFileCreateParam.setDataList(dataList);
        excelFileCreateParam.setClazz(String.class);
        excelFileCreateParam.setFileName(fileName);
        excelFileCreateParam.setReturnWebUrlFlag(true);
        excelFileCreateParam.setListNotLastRow(true);

        return CommonFormOfficeUtils.createExcelAndUpload(excelFileCreateParam);
    }
}
